package com.bacel.nb.product.web.controller;

import com.bacel.nb.product.core.service.ILogsService;
import com.bacel.nb.product.core.service.ISysmoduleService;
import com.bacel.nb.product.web.util.WebUtilify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bacel.nb.product.web.template.ViewModel.FreeMarkerView;

/**
 * Created by liyu on 16/12/26.
 */
@RestController
@RequestMapping(value = "/sysmanage")
public class IndexController{
    @Autowired
    private ISysmoduleService sysmoduleService;

    @RequestMapping(value = "/", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
    public void index(final HttpServletResponse response) throws Exception {
        response.sendRedirect("login");
    }

    @RequestMapping(value = "/main", method = RequestMethod.GET)
    public final ModelAndView main(final HttpSession session, final HttpServletRequest request)
            throws Exception {

        String path = request.getContextPath();
        String menulist = WebUtilify.BuildMenuinfo(path,sysmoduleService);
        // 显示首页
        ModelAndView mav = new FreeMarkerView("main", "首页", path, menulist, session);
        return mav;
    }

    @RequestMapping(value = "/unauth", method = RequestMethod.GET, produces = { "application/json;charset=UTF-8" })
    public String usermgr(HttpServletRequest request) {
        return "{\"code\":-1,\"msg\":\"此功能授权\"";
    }
}
